package top.program.attend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.program.attend.entity.Attend;
import top.program.attend.service.AttendService;
import top.program.attend.vo.QueryCondition;
import top.program.common.page.PageQueryBean;
import top.program.user.entity.User;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/attend")
public class AttendController {

    @Autowired
    private AttendService attendService;

    @RequestMapping
    public String toAttend(){
        return "attend";
    }


    @RequestMapping("/sign")
    @ResponseBody
    public String signAttend(@RequestBody  Attend attend) throws Exception {
        attendService.signAttend(attend);
        return "succ";
    }

    /**
     *@Author xcl
     *@Date 2017/10/17 7:29
     *@Description 考勤数据分页查询
     */
    @RequestMapping("/attendList")
    @ResponseBody
    public PageQueryBean listAttend(QueryCondition queryCondition,HttpSession session){

        User user = (User) session.getAttribute("userinfo");
        String [] rangeDate = queryCondition.getRangeDate().split("/");
        queryCondition.setStartDate(rangeDate[0]);
        queryCondition.setEndDate(rangeDate[1]);
        queryCondition.setUserId(user.getId());

        PageQueryBean result = attendService.listAttend(queryCondition);
        return result;
    }


}
